﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity.ModelConfiguration;
using MyVoteMVC.Domain;

namespace MyVoteMVC.Data.Mapping
{
    public class VT_ActivitiesMap : EntityTypeConfiguration<VT_Activities>
    {
        public VT_ActivitiesMap() {
            // Primary Key
            this.HasKey(t => t.Activity_ID);

            // Properties
            this.Property(t => t.Activity_ID)
                .IsRequired()
                .HasMaxLength(36);

            this.Property(t => t.Activity_PID)
                .HasMaxLength(36);

            this.Property(t => t.Activity_No)
                .IsFixedLength()
                .HasMaxLength(10);

            this.Property(t => t.Activity_Title)
                .HasMaxLength(100);

            this.Property(t => t.Created_By)
                .HasMaxLength(100);

            this.Property(t => t.Created_Action)
                .HasMaxLength(200);

            this.Property(t => t.Last_Update_By)
                .HasMaxLength(100);

            this.Property(t => t.Last_Update_Action)
                .HasMaxLength(200);

            this.Ignore(t => t.Activity_IfReadAllText);
            this.Ignore(t => t.Activity_IfMultiSubmitText);
            this.Ignore(t => t.Activity_IfShowUserText);

            this.ToTable("VT_Activities");
            this.Property(t => t.Activity_ID).HasColumnName("Activity_ID");
            this.Property(t => t.Activity_PID).HasColumnName("Activity_PID");
            this.Property(t => t.Activity_No).HasColumnName("Activity_No");
            this.Property(t => t.Activity_Title).HasColumnName("Activity_Title");
            this.Property(t => t.Activity_Content).HasColumnName("Activity_Content");
            this.Property(t => t.Activity_StartTime).HasColumnName("Activity_StartTime");
            this.Property(t => t.Activity_EndTime).HasColumnName("Activity_EndTime");
            this.Property(t => t.Activity_IfShowUser).HasColumnName("Activity_IfShowUser");
            this.Property(t => t.Activity_IfReadAll).HasColumnName("Activity_IfReadAll");
            this.Property(t => t.Activity_IfMultiSubmit).HasColumnName("Activity_IfMultiSubmit");
            this.Property(t => t.Created_By).HasColumnName("Created_By");
            this.Property(t => t.Created_Date).HasColumnName("Created_Date");
            this.Property(t => t.Created_Action).HasColumnName("Created_Action");
            this.Property(t => t.Last_Update_By).HasColumnName("Last_Update_By");
            this.Property(t => t.Last_Update_Date).HasColumnName("Last_Update_Date");
            this.Property(t => t.Last_Update_Action).HasColumnName("Last_Update_Action");
            this.Property(t => t.View_Count).HasColumnName("View_Count");
            this.Property(t => t.Memo).HasColumnName("Memo");

            this.HasOptional(t => t.ParentActivity)
                .WithMany(t => t.ChildActivities)
                .HasForeignKey(k => k.Activity_PID);

            this.HasRequired(t => t.ActivityImage)
               .WithRequiredPrincipal();
        }
    }

    public class VT_ActivityImageMap : EntityTypeConfiguration<VT_ActivityImage>
    {
        public VT_ActivityImageMap() {

            this.HasKey(t => t.Activity_ID);

            this.ToTable("VT_Activities");
            this.Property(t => t.Activity_Image).HasColumnName("Activity_Image");
            
        }
    }
}
